﻿package 
{
	import fl.controls.Button;
	import fl.controls.ScrollBarDirection;
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import fl.controls.ScrollBarDirection;
	import RollableStrip;
	import RollableStripItem;
	/**
	 * ...
	 * @author ml
	 */
	public class Main extends Sprite 
	{
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			var rollableStripContainer:Sprite = new Sprite();
			addChild(rollableStripContainer);
			var rollableStrip:RollableStrip = new RollableStrip(ScrollBarDirection.VERTICAL);
			for(var i:uint = 0; i < 16; i++){
				var graphic:Sprite = new Sprite();
				graphic.graphics.beginFill(0xff00ff, .5);
				graphic.graphics.drawRect(0, 0, 50, 35);
				graphic.graphics.endFill();
				var textField:TextField = new TextField();
				textField.autoSize = TextFieldAutoSize.LEFT;
				textField.text = '{' + i.toString() + '}';
				graphic.addChild(textField);
				var data:Object = {
					index:i
				};
				var rollableStripItem:RollableStripItem = new RollableStripItem(rollableStripContainer.addChild(graphic), data);
				rollableStrip.add(rollableStripItem);
			}
			rollableStrip.show(8);
			rollableStripContainer.x = rollableStripContainer.y = 50;
			
			var back:TextField = new TextField();
			var forward:TextField = new TextField();
			back.text = '<-- back';
			forward.text = 'next -->';
			back.autoSize = forward.autoSize = TextFieldAutoSize.LEFT;
			back.selectable = forward.selectable = false;
			back.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void{
				rollableStrip.moveBy(-1);
			});
			forward.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void{
				rollableStrip.moveBy(1);
			});
			addChild(back);
			addChild(forward);
			forward.x += 200;
		}
	}
}